<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增表单设计')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-form-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label">表单key：</label>
                <div class="col-sm-8">
                    <input id="formKey" name="formKey" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">表单名：</label>
                <div class="col-sm-8">
                    <input id="formName" name="formName" class="form-control">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">表单类型：</label>
                <div class="col-sm-8">
                    <select name="type" class="form-control m-b" th:with="type=${@dict.getType('act_form_type')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <input name="remark" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('sys_normal_disable')}">
                        <input type="radio" th:id="${'status_' + dict.dictCode}" name="status" th:value="${dict.dictValue}" th:checked="${dict.default}">
                        <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "custForm/form"
        $("#form-form-add").validate({
            focusCleanup: true,
            onkeyup: false,
            rules: {
                formKey: {
                    required: true,
                    remote: {
                        url: prefix + "/formKeyIsExist",     //后台处理程序
                        type: "post",               //数据发送方式
                        data: {                     //要传递的数据
                            formKey: function() {
                                return $("#formKey").val();
                            }
                        },
                        dataFilter: function (res, type) {
                            debugger;
                            var arr = eval("("+res+")");
                            if(arr.code == 0){
                                return true;
                            } else {
                                return false;
                            }
                        }
                    }
                },
                formName: {
                    required: true
                }
            },
            messages: {
                formKey: {
                    required: "请输入表单key",
                    remote: "表单key已存在，请修改"
                },
                formName: {
                    required: "请输入表单名"
                }
            }
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-form-add').serialize());
            }
        }

        function submitHandlerFromDefinition(windowName, content) {
            debugger;
            if ($.validate.form()) {
                var encode = encodeURIComponent(content);
                console.log($('#form-form-add').serialize());
                $.operate.save(prefix + "/add", $('#form-form-add').serialize()+"&content="+encode, function(res){
                    if(res.code == 0){
                        window.parent.parent.$.modal.msgSuccess("创建成功");
                        for(var i=0 ; i<window.parent.parent.length ; i++){
                            if(window.parent.parent[i].name == windowName){
                                window.parent.parent[i].resetSelect2();
                            }
                        }
                        $.modal.close();
                        window.parent.$.modal.closeTab();
                    } else {
                        window.parent.parent.$.modal.msgSuccess("创建失败！");
                    }
                });
            }
        }
    </script>
</body>
</html>